#include "Cheats.h"

Cheats g_pCheats;


void Cheats::Init()
{
	this->Active = true;
	this->Fullbright = false;
	this->Whitewalls = false;
	this->Psychedelik = false;
	this->Disco = false;
	this->HideEntities = false;
	this->SimplifyEntities = false;
	this->Wireframe = false;
	this->ChromeModels = false;
	this->ChromeFloor = false;
	this->NoSky = true;
	this->Colorize = false;
	this->Asus = false;
	this->FullbrightPtr = (DWORD*) ((DWORD) GetModuleHandle(L"materialsystem.dll") + 0x10C4A0); // TODO SEARCHPATTERN!
	this->ProxyPtr = (DWORD*) ((DWORD) GetModuleHandle(L"materialsystem.dll") + 0x10C6E0); // TODO SEARCHPATTERN!
	this->DrawEntitiesPtr = (DWORD*) ((DWORD) GetModuleHandle(L"engine.dll") + 0x585638); // TODO SEARCHPATTERN!
	this->DrawOtherModelsPtr = (DWORD*) ((DWORD) GetModuleHandle(L"client.dll") + 0x78DAD0); // TODO SEARCHPATTERN!
	this->ShowEnvCubeMapPtr = (DWORD*) ((DWORD) GetModuleHandle(L"engine.dll") + 0x585368); // TODO SEARCHPATTERN!
	this->FastNoBumpPtr = (DWORD*) ((DWORD) GetModuleHandle(L"materialsystem.dll") + 0x10C800); // TODO SEARCHPATTERN!
	this->SkyboxPtr = (DWORD*) ((DWORD) GetModuleHandle(L"client.dll") + 0x7C7178); // TODO SEARCHPATTERN!
	this->ClearPtr = (DWORD*) ((DWORD) GetModuleHandle(L"client.dll") + 0x7C4728); // TODO SEARCHPATTERN!
	this->MipLevelPtr = (DWORD*) ((DWORD) GetModuleHandle(L"materialsystem.dll") + 0x10BEB8); // TODO SEARCHPATTERN!
}

void Cheats::Enable()
{
	this->Active = true;
}

void Cheats::Disable()
{
	this->Active = false;
}

void Cheats::Set( bool Active )
{
	this->Active = Active;
}

void Cheats::SetFullbright( bool Active )
{
	this->Fullbright = Active;
}

void Cheats::SetWhitewalls( bool Active )
{
	this->Whitewalls = Active;
}

void Cheats::SetPsychedelik( bool Active )
{
	this->Psychedelik = Active;
}

void Cheats::SetDisco( bool Active )
{
	this->Disco = Active;
}

void Cheats::SetHideEntities( bool Active )
{
	this->HideEntities = Active;
}

void Cheats::SetSimplifyEntities( bool Active )
{
	this->SimplifyEntities = Active;
}

void Cheats::SetWireframe( bool Active )
{
	this->Wireframe = Active;
}

void Cheats::SetChromeModels( bool Active )
{
	this->ChromeModels = Active;
}

void Cheats::SetChromeFloor( bool Active )
{
	this->ChromeFloor = Active;
}

void Cheats::SetNoSky( bool Active )
{
	this->NoSky = Active;
}

void Cheats::SetColorize( bool Active )
{
	this->Colorize = Active;
}

void Cheats::SetAsus( bool Active )
{
	this->Asus = Active;
}

void Cheats::Compute()
{
	if (Active)
	{
		if (Fullbright)
		{
			*FullbrightPtr = 1;
		}
		if (Whitewalls)
		{
			*FullbrightPtr = 2;
		}
		if (Psychedelik)
		{
			*ProxyPtr = 2;
		}
		if (Disco)
		{
			*ProxyPtr = 3;
		}
		if (HideEntities)
		{
			*DrawEntitiesPtr = 0;
		}
		if (SimplifyEntities)
		{
			*DrawEntitiesPtr = 3;
		}
		if (Wireframe)
		{
			*DrawOtherModelsPtr = 2;
		}
		if (ChromeModels)
		{
			*ShowEnvCubeMapPtr = 1;
		}
		if (ChromeFloor)
		{
			*FastNoBumpPtr = 1;
		}
		if (NoSky)
		{
			*SkyboxPtr = 0;
			*ClearPtr = 1;
		}
		if (Colorize)
		{
			*MipLevelPtr = 1;
		}
	}
	else
	{
		*FullbrightPtr = 0;
		*ProxyPtr = 0;
		*DrawEntitiesPtr = 1;
		*DrawOtherModelsPtr = 1;
		*ShowEnvCubeMapPtr = 0;
		*FastNoBumpPtr = 0;
		*SkyboxPtr = 1;
		*MipLevelPtr = 0;
		*ClearPtr = 0;
	}
}

void Cheats::ComputeAsus( IMaterial* Mat )
{
	if (Asus)
	{
		Mat->AlphaModulate(0.9f);
	}
}
